<!DOCTYPE HTML PUBLIC "-//ORA//DTD CD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>[Chapter 30] The java.util Package</TITLE>
<META NAME="author" CONTENT="David Flanagan">
<META NAME="date" CONTENT="Thu Jul 31 16:34:41 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="Java">
<META NAME="title" CONTENT="Java in a Nutshell">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">
<script language='JavaScript'>
<!--
if (location.replace) {
 location.replace ('ch30_js.htm');
}
// -->
</script>

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java in a Nutshell" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch29_19.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 30</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch30_02.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<H1 CLASS=chapter><A CLASS="TITLE" NAME="JNUT2-CH-30">30. The java.util Package</A></H1>

<DIV CLASS=htmltoc>

<p>
<b>Contents:</b><br>
<a href='ch30_02.htm'>java.util.Calendar (JDK 1.1)</a><br>
<a href='ch30_03.htm'>java.util.Date (JDK 1.0)</a><br>
<a href='ch30_04.htm'>java.util.Dictionary (JDK 1.0)</a><br>
<a href='ch30_05.htm'>java.util.EmptyStackException (JDK 1.0)</a><br>
<a href='ch30_06.htm'>java.util.Enumeration (JDK 1.0)</a><br>
<a href='ch30_07.htm'>java.util.EventListener (JDK 1.1)</a><br>
<a href='ch30_08.htm'>java.util.EventObject (JDK 1.1)</a><br>
<a href='ch30_09.htm'>java.util.GregorianCalendar (JDK 1.1)</a><br>
<a href='ch30_10.htm'>java.util.Hashtable (JDK 1.0)</a><br>
<a href='ch30_11.htm'>java.util.ListResourceBundle (JDK 1.1)</a><br>
<a href='ch30_12.htm'>java.util.Locale (JDK 1.1)</a><br>
<a href='ch30_13.htm'>java.util.MissingResourceException (JDK 1.1)</a><br>
<a href='ch30_14.htm'>java.util.NoSuchElementException (JDK 1.0)</a><br>
<a href='ch30_15.htm'>java.util.Observable (JDK 1.0)</a><br>
<a href='ch30_16.htm'>java.util.Observer (JDK 1.0)</a><br>
<a href='ch30_17.htm'>java.util.Properties (JDK 1.0)</a><br>
<a href='ch30_18.htm'>java.util.PropertyResourceBundle (JDK 1.1)</a><br>
<a href='ch30_19.htm'>java.util.Random (JDK 1.0)</a><br>
<a href='ch30_20.htm'>java.util.ResourceBundle (JDK 1.1)</a><br>
<a href='ch30_21.htm'>java.util.SimpleTimeZone (JDK 1.1)</a><br>
<a href='ch30_22.htm'>java.util.Stack (JDK 1.0)</a><br>
<a href='ch30_23.htm'>java.util.StringTokenizer (JDK 1.0)</a><br>
<a href='ch30_24.htm'>java.util.TimeZone (JDK 1.1)</a><br>
<a href='ch30_25.htm'>java.util.TooManyListenersException (JDK 1.1)</a><br>
<a href='ch30_26.htm'>java.util.Vector (JDK 1.0)</a><br>
<p>
<p>
</DIV>

<P CLASS=para>
The <tt CLASS=literal>java.util</tt> package defines a number of useful
classes. This package should not be considered a "utility"
package separate from the rest of the language; in fact,
Java depends directly on several of the classes in this
package.
<A HREF="ch30_01.htm#JNUT2-CH-30-FIG-1">Figure 30.1</A>
shows the class hierarchy of this package.<A NAME="CH30.JAVA.UTIL.PA1"></A>

<DIV CLASS=figure>
<h4 CLASS=figure><A CLASS="TITLE" NAME="JNUT2-CH-30-FIG-1">Figure 30.1: The java.util package</A></h4>


<p>
<img align=middle src="./figs/jn2_3001.gif" alt="[Graphic: Figure 30-1]" width=464 height=567 border=0>

</DIV>

<P CLASS=para>
The <tt CLASS=literal>Hashtable</tt> class is one of the most useful in the
package--it implements a hashtable or associative array. It
allows arbitrary objects to be stored and retrieved by
arbitrary keys. The <tt CLASS=literal>Properties</tt> subclass of
<tt CLASS=literal>Hashtable</tt> is used to store the Java system
properties list.

<P CLASS=para>
<tt CLASS=literal>Vector</tt> is another extremely useful class. It
implements an array of objects that grows as needed
when objects are added.

<P CLASS=para>
The <tt CLASS=literal>Enumeration</tt> interface provides a simple and
consistent way to loop through all the elements contained
within some kind of object or data structure.

<P CLASS=para>
The <tt CLASS=literal>Date</tt> class represents a date and time, using a
millisecond representation.  In Java 1.1, the
<tt CLASS=literal>Calendar</tt> class manipulates dates using more familiar
units such as months, days, hours, and minutes.  The
<tt CLASS=literal>TimeZone</tt> class is also used in conjunction with
dates.

<P CLASS=para>
In Java 1.1, <tt CLASS=literal>ResourceBundle</tt> and its subclasses,
<tt CLASS=literal>ListResourceBundle</tt> and <tt CLASS=literal>PropertyResourceBundle</tt>,
represent a
"bundle" of localized resources that are read in by an
internationalized program at runtime.

<P CLASS=para>
The remaining classes are also useful. <tt CLASS=literal>BitSet</tt>
implements an arbitrary-size array of bits. <tt CLASS=literal>Random</tt>
generates and returns pseudo-random numbers in a variety of
forms. <tt CLASS=literal>StringTokenizer</tt> parses a string into tokens.
<tt CLASS=literal>Stack</tt> implements a last-in-first-out stack on which
objects may be pushed, and from which they may be popped.
And the <tt CLASS=literal>Observer</tt> interface and <tt CLASS=literal>Observable</tt>
class provide infrastructure for implementing the
object-oriented model-view paradigm in Java.

<DIV CLASS=sect1>
<h2 CLASS=sect1><A CLASS="TITLE" NAME="JNUT2-CH-30-SECT-1">30.1 java.util.BitSet (JDK 1.0)</A></h2>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JNUT2-CH-30-SECT-1.1"></A></h3>
</DIV>

<P CLASS=para>
This class defines an arbitrarily large set of bits.
Instance methods allow you to set, clear, and query
individual bits in the set, and also to perform bitwise
boolean arithmetic on the bits in <tt CLASS=literal>BitSet</tt> objects.
This class can be used as an extremely compact array of
boolean values, although reading and writing those values is
slower than normal array access.

<DIV CLASS=screen>
<P>
<PRE>
public final class <tt CLASS=literal>BitSet</tt> extends Object implements Cloneable, Serializable {
    // <tt CLASS=literal>Public Constructors</tt>
            public <tt CLASS=literal>BitSet</tt>();
            public <tt CLASS=literal>BitSet</tt>(int <tt CLASS=literal>nbits</tt>);
    // <tt CLASS=literal>Public Instance Methods</tt>
            public void <tt CLASS=literal>and</tt>(BitSet <tt CLASS=literal>set</tt>);
            public void <tt CLASS=literal>clear</tt>(int <tt CLASS=literal>bit</tt>);
            public Object <tt CLASS=literal>clone</tt>();  //<tt CLASS=literal> Overrides Object</tt>
            public boolean <tt CLASS=literal>equals</tt>(Object <tt CLASS=literal>obj</tt>);  //<tt CLASS=literal> Overrides Object</tt>
            public boolean <tt CLASS=literal>get</tt>(int <tt CLASS=literal>bit</tt>);
            public int <tt CLASS=literal>hashCode</tt>();  //<tt CLASS=literal> Overrides Object</tt>
            public void <tt CLASS=literal>or</tt>(BitSet <tt CLASS=literal>set</tt>);
            public void <tt CLASS=literal>set</tt>(int <tt CLASS=literal>bit</tt>);
            public int <tt CLASS=literal>size</tt>();
            public String <tt CLASS=literal>toString</tt>();  //<tt CLASS=literal> Overrides Object</tt>
            public void <tt CLASS=literal>xor</tt>(BitSet <tt CLASS=literal>set</tt>);
}
</PRE>
</DIV>

</DIV>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JNUT2-CH-30-SECT-1.2">Passed To:</A></h3>

<P CLASS=para>
BitSet.and(), 
BitSet.or(), 
BitSet.xor()

</DIV>

</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch29_19.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch30_02.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>java.text.StringCharacterIterator (JDK 1.1)</td>
<td width=171 align=center valign=top><a href="index/idx_0.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>java.util.Calendar (JDK 1.1)</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
